﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Google.GData.Client;
using Google.GData.Extensions;
using Google.GData.Extensions.Location;
using Google.GData.Photos;
using OpenSocialPlugin.General;
using OpenSocialPlugin.Providers;

namespace test
{
    public partial class Form1 : Form
    {
        ISocialSite site = new Facebook();
        public Form1()
        {
            InitializeComponent();
            site.Init();
            site.Home();
            textBox1.Text = site.Login().Id;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //OSP_Person pers = new OSP_Person();
            //PicasaService service = new PicasaService("SocialPluginForMediaPortal");


            //AlbumQuery query = new AlbumQuery(PicasaQuery.CreatePicasaUri("dukusi"));

            //PicasaFeed feed = service.Query(query);

            //foreach (PicasaEntry entry in feed.Entries)
            //{
            //    Console.WriteLine(entry.Title.Text);
            //    AlbumAccessor ac = new AlbumAccessor(entry);
            //    Console.WriteLine(ac.NumPhotos);
                
            //    PhotoQuery query1 = new PhotoQuery(PicasaQuery.CreatePicasaUri("dukusi", ac.Id));

            //    PicasaFeed feed1 = service.Query(query1);

            //    foreach (PicasaEntry entry1 in feed1.Entries)
            //    {
            //        Console.WriteLine(entry1.Title.Text);
            //    }
            //}


          listBox1.Items.Clear();


          List<OSP_Person> pers = site.GetFriends(new OSP_Person(textBox1.Text));
          foreach (OSP_Person per in pers)
          {
            listBox1.Items.Add(per);
          }
          List<OSP_Album> albums = site.GetAlbums(new OSP_Person(textBox1.Text));
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                textBox1.Text = ((OSP_Person)listBox1.SelectedItem).Id;
                pictureBox1.ImageLocation = ((OSP_Person)listBox1.SelectedItem).LargeThumb;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            listBox2.Items.Clear();
            List<OSP_Album> albums = site.GetAlbums(new OSP_Person(textBox1.Text));
            foreach(OSP_Album alb in albums)
            {
                listBox2.Items.Add(alb);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {

            listBox3.Items.Clear();
            List<OSP_Photo> ph = site.GetPhotos(((OSP_Album)listBox2.SelectedItem));
            foreach (OSP_Photo photo in ph)
            {
                listBox3.Items.Add(photo);
            }
        }

        private void listBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            pictureBox1.ImageLocation = ((OSP_Photo)listBox3.SelectedItem).Url;
        }
    }
}
